home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / readers / skim-0.8 / skim-0 / skim-0.8.4 / RebuildArticleIndexes.c < prev    next >
C/C++ Source or Header  |  1996-02-18  |  4KB  |  130 lines

  1. /*
  2.  * NAME
  3.  *   RebuildArticleIndexes.c
  4.  * DESCRIPTION
  5.  *   Rebuild all of skim's article indexes.
  6.  * COPYRIGHT
  7.  *   Skim - Off-line news reading package optimized for slow lines.
  8.  *   Copyright (C) 1996  Rene W.J. Pijlman
  9.  *
  10.  *   This program is free software; you can redistribute it and/or modify
  11.  *   it under the terms of the GNU General Public License as published by
  12.  *   the Free Software Foundation; either version 2 of the License, or
  13.  *   (at your option) any later version.
  14.  * 
  15.  *   This program is distributed in the hope that it will be useful,
  16.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *   GNU General Public License for more details.
  19.  * 
  20.  *   You should have received a copy of the GNU General Public License
  21.  *   along with this program; if not, write to the Free Software
  22.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  * VERSION
  24.  *   Skim version 0.8.4.
  25.  */
  26.  
  27. #include <dirent.h>
  28.  
  29. #include "VarBuf.h"
  30. #include "Skim.h"
  31. #include "SkimUtils.h"
  32. #include "StandardIO.h"
  33.  
  34. FILE_ID("$Header: /home/rene/sys/CVS_MasterSourceRepository/skim/RebuildArticleIndexes.c,v 1.5 1996/02/17 22:47:35 rene Exp $" );
  35.  
  36. int main( int argc, char ** argv )
  37. {
  38.     StandardIO ArticleIndex = SIOCreate();
  39.     VarBuf NewsGroup = VBCreate();
  40.     VarBuf ArticleDirectoryName = VBCreate();
  41.     VarBuf ArticleFileName = VBCreate();
  42.     VarBuf ArticleNumber = VBCreate();
  43.     VarBuf IndexFileName = VBCreate();
  44.     struct dirent * DirectoryEntry;
  45.     DIR * ArticleDirectory;
  46.  
  47.     if ( argc != 1 )
  48.     {
  49.         SIOPrintf( StandardError, "RebuildArticleIndexes\n" );
  50.         exit( EXIT_FAILURE );
  51.     }
  52.  
  53.     VBPrintf( ArticleDirectoryName, "%s/Art", SkimDirectory() );
  54.  
  55.     ArticleDirectory = opendir( VBAsString(ArticleDirectoryName) );
  56.     if ( ArticleDirectory == NULL )
  57.     {
  58.         SIOPrintf( StandardError, "Error opening directory %s\n", 
  59.                  VBAsString(ArticleDirectoryName) );
  60.         exit( EXIT_FAILURE );
  61.     }
  62.  
  63.     while ( ( DirectoryEntry = readdir( ArticleDirectory ) ) != NULL )
  64.     {
  65.         /* Skip "." and "..", and possibly other dot files as well. */
  66.         if ( DirectoryEntry->d_name[0] != '.' )
  67.         {
  68.         char * LastDot = NULL;
  69.         char * p;
  70.  
  71.         for ( p = DirectoryEntry->d_name;
  72.           *p != '\0';
  73.           p++ )
  74.         {
  75.             if ( *p == '.' )
  76.             {
  77.                 LastDot = p;
  78.             }
  79.         }
  80.  
  81.         if ( LastDot == NULL )
  82.         {
  83.         SIOPrintf( StandardError,
  84.                            "Incorrect file name: %s\n",
  85.                    DirectoryEntry->d_name );
  86.         exit( EXIT_FAILURE );
  87.         }
  88.  
  89.         for ( p = DirectoryEntry->d_name; p < LastDot; p++ )
  90.         {
  91.         VBAppendCharacter( NewsGroup, *p );
  92.         }
  93.  
  94.         for ( p = LastDot + 1; *p != '\0'; p++ )
  95.         {
  96.         VBAppendCharacter( ArticleNumber, *p );
  97.         }
  98.  
  99.         VBPrintf( IndexFileName,
  100.               "%s/Indexes/Articles/%V",
  101.               SkimDirectory(), NewsGroup );
  102.         VBPrintf( ArticleFileName, "%V/%s",
  103.               ArticleDirectoryName, DirectoryEntry->d_name );
  104.  
  105.         SIOFileOpenVB( ArticleIndex, IndexFileName, OpenModeAppend );
  106.  
  107.         AddArticleToIndex( ArticleFileName, ArticleNumber, ArticleIndex );
  108.  
  109.         SIOFileClose( ArticleIndex );
  110.  
  111.         VBReset( NewsGroup );
  112.         VBReset( ArticleFileName );
  113.         VBReset( ArticleNumber );
  114.         VBReset( IndexFileName );
  115.     }
  116.     }
  117.  
  118.     (void)closedir( ArticleDirectory );
  119.  
  120.     VBDestroy( NewsGroup );
  121.     VBDestroy( ArticleDirectoryName );
  122.     VBDestroy( ArticleFileName );
  123.     VBDestroy( ArticleNumber );
  124.     VBDestroy( IndexFileName );
  125.  
  126.     SIODestroy(ArticleIndex);
  127.  
  128.     return EXIT_SUCCESS;
  129. }
  130.